package cn.itsource.blog.service.impl;

import cn.itsource.blog.domain.Comment;
import cn.itsource.blog.repository.CommentRepository;
import cn.itsource.blog.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements ICommentService {
    @Autowired
    private CommentRepository commentRepository;

    @Override
    public List<Comment> findByArticleId(Long articleId) {
        return commentRepository.findByArticleId(articleId);
    }
    @Override
    public void add(Comment comment) {
        commentRepository.save(comment);//没有主键id就是添加
    }
    @Override
    public void update(Comment comment) {
        commentRepository.save(comment);//有主键id就是修改
    }
    //评论是保存在mongodb - mongodb中的主键id是String
    @Override
    public void delete(String id) {
        commentRepository.deleteById(id);
    }
}
